package com.threadpool.mythread.case01;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Author 李李李
 * @2020/4/26 20:43
 *
 * SynchronousQueue 同步队列
 *
 */
public class Case10 {
    public static void main(String[] args) {
        SynchronousQueue synchronousQueue = new SynchronousQueue();

        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "===> put A");
            synchronousQueue.offer("A");
            System.out.println(Thread.currentThread().getName() + "===> put B");
            synchronousQueue.offer("B");
            System.out.println(Thread.currentThread().getName() + "===> put C");
            synchronousQueue.offer("C");
        },"A").start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName() + "===> get " + synchronousQueue.take());
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName() + "===> get " + synchronousQueue.take());
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName() + "===> get " + synchronousQueue.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"B").start();

    }
}
